﻿using AEFunction.UI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using System;
using System.Windows.Forms;
namespace CommonFunction
{
    public partial class CMenuStrip : Control
    {
        public ILayer layer = new FeatureLayerClass();
        public AxMapControl axMapControl1;
        AttributeTableDlg attributeDlg;
        public CMenuStrip(ILayer l, AxMapControl mapControl, ref AttributeTableDlg atDlg)
        {
            InitializeComponent();
            layer = l;
            axMapControl1 = mapControl;
            if (atDlg.IsDisposed == true)
                atDlg = new AttributeTableDlg();
            attributeDlg = atDlg;
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }

        private void openAttributeTable_Click(object sender, EventArgs e)
        {
            if (attributeDlg.layers.Count == 0)
            {
                attributeDlg.Init(layer, axMapControl1);
                attributeDlg.Show();
            }
            else
            {
                attributeDlg.AddNewLayer(layer);

                attributeDlg.SwithTabControl(attributeDlg.layers.Count - 1);
            }
            contextMenuStrip1.Items.Clear();
            contextMenuStrip1.Dispose();
            this.Dispose();
        }

        private void deleteLayer(object sender, EventArgs e)
        {
            axMapControl1.Map.DeleteLayer(layer);
            contextMenuStrip1.Items.Clear();
            contextMenuStrip1.Dispose();
            attributeDlg.RemoveTabControl(layer);
            this.Dispose();
        }

        private void ZoomToLayer(object sender, EventArgs e)
        {
            axMapControl1.ActiveView.Extent = layer.AreaOfInterest;
            contextMenuStrip1.Items.Clear();
            contextMenuStrip1.Dispose();
            this.Dispose();
        }

        private void setMaxVisiableScale_Click(object sender, EventArgs e)
        {

        }

        private void setMinVisiableScale_Click(object sender, EventArgs e)
        {

        }
    }
}
